package com.patterns.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * 查杀文件夹文件
 * @author huangke
 *
 */
public class FolderVirus implements AntivirusSoftware{
	
	private String folderName;
	// 文件夹下的子文件
	private List<AntivirusSoftware> children = new ArrayList<AntivirusSoftware>();
	
	public FolderVirus(String folderName) {
		this.folderName = folderName;
	}


	public void killVirus() {
		System.err.println("查杀文件夹病毒文件:" + folderName);
		// 递归查杀文件夹下的文件
		for (AntivirusSoftware a : children) {
			a.killVirus();
		}
	}
	
	
	/**********容器节点独有方法，用于操作节点***********/
	public void add(AntivirusSoftware a){
		this.children.add(a);
	}
	
	public void remove(AntivirusSoftware a){
		this.children.remove(a);
	}
	
	public void remove(int index){
		this.children.remove(index);
	}
	
	public AntivirusSoftware getChild(int index){
		return this.children.get(index);
	}

}
